package com.miaoquan.mqportal.service.impl;

import com.github.pagehelper.PageHelper;
import com.miaoquan.mqmbg.mapper.TbkProductMapper;
import com.miaoquan.mqmbg.model.TbkProduct;
import com.miaoquan.mqmbg.model.TbkProductExample;
import com.miaoquan.mqportal.domain.TbkProductItem;
import com.miaoquan.mqportal.service.TbkProductService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * 淘宝客商品Service实现类
 *
 * @author Fa
 * @date 2020-03-29 18:16
 */
@Service
public class TbkProductServiceImpl implements TbkProductService {

    @Autowired
    private TbkProductMapper tbkProductMapper;

    @Override
    public List<TbkProduct> getList(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return tbkProductMapper.selectByExample(new TbkProductExample());
    }

    @Override
    public TbkProductItem getItem(Long itemId) {
        TbkProductExample tbkProductExample = new TbkProductExample();
        tbkProductExample.createCriteria().andItemIdEqualTo(itemId);
        List<TbkProduct> tbkProductList = tbkProductMapper.selectByExample(tbkProductExample);
        if (!CollectionUtils.isEmpty(tbkProductList)) {
            TbkProductItem tbkProductItem = new TbkProductItem();
            BeanUtils.copyProperties(tbkProductList.get(0), tbkProductItem);
            return tbkProductItem;
        }
        return null;
    }

}
